﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "Widget/SSwitch.h"

SSwitch::SSwitch()
{
	
}

void SSwitch::Construct(const FArguments& InArgs)
{
	SwitchPosition = InArgs._SwitchPosition.Get();
	IconWidth = InArgs._IconWidth.Get();
	BorderImage = InArgs._BorderImage.Get();
	LeftLabelText = InArgs._LeftLabelText;
	LeftLabelFont = InArgs._LeftLabelFont.Get();
	RightLabelText = InArgs._RightLabelText;
	RightLabelFont = InArgs._RightLabelFont.Get();
	
	ChildSlot
	[
		SAssignNew(OuterBox, SBox)
		.HAlign(EHorizontalAlignment::HAlign_Fill)
		.VAlign(EVerticalAlignment::VAlign_Fill)
    	[
    	    SAssignNew(HorizontalLayout,SHorizontalBox)
    	    
    	    +SHorizontalBox::Slot()
    	    .HAlign(EHorizontalAlignment::HAlign_Fill)
    	    .VAlign(EVerticalAlignment::VAlign_Fill)
    		.Padding( FMargin( 0, 0, 0, 0 ) )
    		.AutoWidth()
    		[
    		    SAssignNew(LeftLabelBox,SBox)
    		    .HAlign(EHorizontalAlignment::HAlign_Fill)
				.VAlign(EVerticalAlignment::VAlign_Fill)
    		    [
    				SAssignNew(LeftLabel,STextBlock)
    				.Text(LeftLabelText)
    				.Font(LeftLabelFont)
    		    ]
    		]
    		
    		+SHorizontalBox::Slot()
    		.HAlign(EHorizontalAlignment::HAlign_Fill)
            .VAlign(EVerticalAlignment::VAlign_Fill)
            .Padding( FMargin( 0, 0, 0, 0 ) )
            .FillWidth(1.0f)
            [
                SAssignNew(SwitchBox,SBox)
                .HAlign(EHorizontalAlignment::HAlign_Fill)
				.VAlign(EVerticalAlignment::VAlign_Fill)
				.Padding(0.f)
                [
                    SAssignNew(SwitchButton,SButton)
                    .HAlign(SwitchPosition)
                    .VAlign(EVerticalAlignment::VAlign_Fill)
                    [
            		    SAssignNew(SwitchBorder,SBorder)
            		    .HAlign(EHorizontalAlignment::HAlign_Fill)
            		    .VAlign(EVerticalAlignment::VAlign_Fill)
            		    .BorderImage(BorderImage)
            		    [
            				SAssignNew(SwitchSize,SBox)
            				.WidthOverride(IconWidth)
            		    ]
            		]
                    
                ]
            ]
            
            +SHorizontalBox::Slot()
            .HAlign(EHorizontalAlignment::HAlign_Fill)
            .VAlign(EVerticalAlignment::VAlign_Fill)
            .Padding( FMargin( 0, 0, 0, 0 ) )
            .AutoWidth()
            [
                SAssignNew(RightLabelBox,SBox)
                .HAlign(EHorizontalAlignment::HAlign_Fill)
				.VAlign(EVerticalAlignment::VAlign_Fill)
                [
                    SAssignNew(RightLabel,STextBlock)
                    .Text(RightLabelText)
                    .Font(RightLabelFont)
                ]
            ]
    	]
	];
}

void SSwitch::SetSwitchPosition(EHorizontalAlignment value)
{
	if(SwitchButton.IsValid())
	{
		SwitchPosition = value;
		SwitchButton->SetHAlign(SwitchPosition);
	}
}

void SSwitch::SetIconWidth(float value)
{
	if(SwitchSize.IsValid())
    {
    	IconWidth = value;
    	SwitchSize->SetWidthOverride(IconWidth);
    }
}

void SSwitch::SetBorderImage(FSlateBrush* value)
{
	if(SwitchBorder.IsValid())
	{
		BorderImage = value;
		SwitchBorder->SetBorderImage(BorderImage);
	}
}

void SSwitch::SetLeftLabelText(FText value)
{
	LeftLabelText = value;
	LeftLabel->SetText(LeftLabelText);
}
void SSwitch::SetLeftLabelFont(FSlateFontInfo value)
{
	LeftLabelFont = value;
	LeftLabel->SetFont(LeftLabelFont);
}
void SSwitch::SetRightLabelText(FText value)
{
	RightLabelText = value;
	RightLabel->SetText(RightLabelText);
}
void SSwitch::SetRightLabelFont(FSlateFontInfo value)
{
	RightLabelFont = value;
	RightLabel->SetFont(RightLabelFont);
}
